package com.woniuxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.mapper.SysRoleMapper;
import com.woniuxy.pojo.SysRole;
import com.woniuxy.pojo.dto.SysRoleDTO;
import com.woniuxy.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author Administrator
 * @description 针对表【t_sys_role】的数据库操作Service实现
 * @createDate 2025-06-04 15:19:25
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole>
        implements SysRoleService {
    @Autowired
    SysRoleMapper sysRoleMapper;
    @Override
    public List<SysRoleDTO> getAllRoles() {
        return sysRoleMapper.getAllRoles();
    }

    @Override
    public Boolean updateStatus(SysRole sysRole) {
        LambdaUpdateWrapper<SysRole> wrapper = Wrappers.lambdaUpdate();
        wrapper.eq(SysRole::getId,sysRole.getId())
                .set(SysRole::getRoleStatus,sysRole.getRoleStatus());

        return sysRoleMapper.update(null,wrapper) > 0;
    }

    @Override
    public Boolean addNewRole(SysRole sysRole) {
        sysRole.setCreateTime(new Date());
        sysRole.setUserCount(0);
        return sysRoleMapper.insert(sysRole) > 0;
    }

    @Override
    public Boolean updateRole(SysRole sysRole) {
        int rows = sysRoleMapper.updateById(sysRole);
        return rows > 0;
    }

    @Override
    public Boolean deleteRole(Integer id) {
        int rows = sysRoleMapper.deleteById(id);
        return rows > 0;
    }
}




